<?php
/*
 * Data Explorer: Footnote Insertion Driver
 *      "footnoteDriver.php"
 *
 * last modified: 2/22/11
 * author: James Duran
 *
 * description: provides a mysql interface for selecting and
 *              inserting footnotes.
 *
 * comments: n/a
 */
require_once "mysqlDriver.php";

$dataset = $_REQUEST["ds"];
$attributeName = $_REQUEST["attr"];
$body = $_REQUEST["footnoteBody"];

if($dataset != "" && $attributeName != "" && $body != "") {
    sqlInsert("insert into `attribute_footnotes` (`id`, `ds_name`, `attr_name`," .
              " `created`, `body`) values (null, '$dataset', '$attributeName', null, '$body')");

    echo "Thanks! Your footnote has been added.";
} elseif($dataset != "" && $attributeName != "") {
    $_array = array();
    $_result = sqlSelect("select * from `attribute_footnotes` where `ds_name` like '%$dataset%' and `attr_name` like '%$attributeName%' order by `created` desc");

    while($_row = mysql_fetch_assoc($_result)) {
        $_arrayRow['dataset'] = $_row['ds_name'];
        $_arrayRow['attribute'] = $_row['attr_name'];
        $_arrayRow['footnote'] = $_row['body'];
        $_arrayRow['created'] = date("D, d M Y H:i", strtotime($_row['created']));
        array_push($_array, $_arrayRow);
    }
    mysql_free_result($_result);
    echo json_encode($_array);
}
?>
